﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Free2AskModel;
using System.Web.Security;
namespace Free2AskWeb.Controllers
{
    public class AnswerController : Controller
    {
        //
        // GET: /Answer/
        Free2AskDBEntities db;

        public AnswerController()
        {
            db = new Free2AskDBEntities();
        }

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult PostAnswer(Answer answer)
        {
            if (answer.PostContent!=null&&answer.PostContent.Trim() != "")
            {
                answer.DatetimePosted = DateTime.Now;
                answer.AuthorID = new Guid(Membership.GetUser().ProviderUserKey.ToString());
                db.Posts.AddObject(answer);
                db.SaveChanges();
            }
            //return RedirectToAction("Details", "Question", new { questionID = answer.QuestionID });
            return Json(answer.QuestionID);
        }

    }
}
